#include <rtthread.h>
#include <dfs_fs.h>
#include <rtdbg.h>

#define THREAD_STACK_SIZE 2048
#define THREAD_NAME "sd_mount_task"

static rt_thread_t sd_thread;

extern uint8_t inited;

void sd_mount_entry(void *p)
{
	while (1)
	{
		rt_thread_mdelay(200);

		if (rt_device_find("sd0") != RT_NULL)
		{
			if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
			{
				LOG_I("sd card mount to '/'");
				break;
			}
			else
			{
				LOG_W("sd card mount to '/' failed!");
			}
		}
	}
}

int sd_init(void)
{
	rt_err_t ret;
	sd_thread = rt_thread_create(THREAD_NAME, sd_mount_entry, NULL, THREAD_STACK_SIZE, 20, 20);
	if (sd_thread)
	{
		rt_thread_startup(sd_thread);
		return 0;
	}
	return -1;
}

INIT_APP_EXPORT(sd_init);
